<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>数据类型</title>
    </head>
    <body>
      <script>
        /*
        * JS数据类型 = 原始类型 + 引用类型
        * 原始类型：number string boolean undefined null
        * typeof 用来推断数据类型
        * */
        var a = 10;
        var b = 3.14;
        console.log(a,typeof a,b,typeof b);//10 number 3.14 number
        var d = '你好';
        var e = "你好2";
        console.log(d,typeof d,e,typeof e);//你好 string 你好2 string
        var f = true;
        var g = false;
        console.log(f,typeof f,g,typeof g);//true boolean false boolean
        var h;//未定义，默认undefined
        console.log(h,typeof h);//undefined undefined

        //引用类型 Object Array Function Number Boolean
        let obj = {};
        console.log(obj,typeof obj);//{} 'object'
        let obj2 = {
            name:'张三',
            age:18
        };
        console.log(obj2,typeof obj2);//{} 'object'
        console.log(obj2.name,obj2.age);
        obj2.age = 19;
        console.log(obj2.age);
        //JS可以动态的往对象中新增属性
        obj2.like = '吃火锅';
        console.log(obj2);//{ name: '张三', age: 19, sex: '吃火锅' }
        obj2.play;
        console.log(obj2.play);//undefined

        //JS数组
        let arr = ['周一',3,4.6,true];
        console.log(arr);
        console.log(arr[0],arr[1],arr[2],arr[3]);
        console.log(arr[99]);//访问数组不存在的下标会得到undefined

        //Boolean()用于将参数转为布尔类型
        //0,undefined,null,NaN,false,空字符串转为false(特殊)
        console.log(Boolean(0));//false
        console.log(Boolean(undefined));//false
        console.log(Boolean(null));//false
        console.log(Boolean(''));//false
        console.log(Boolean(NaN));//false
        console.log(Boolean(false));//false
        console.log(Boolean(' '));//true
        console.log(Boolean(1));//true
        console.log(Boolean('早'));//true

        //Number()用于将参数转为数值类型,如果得不到数值结果，则返回NaN(Not a Number)
        console.log(Number(true),typeof Number(true));//1 'number'
        console.log(Number(false),typeof Number(false));//0 'number'
        console.log(Number(3),typeof Number(3));//3 'number'
        console.log(Number('3'),typeof Number('3'));//3 'number'
        console.log(Number('困困困'),typeof Number('困困困'));//NaN 'number'

      </script>
    </body>
</html>